package com.dcbeida.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Pair;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.dcbeida.R;
import com.dcbeida.activity.hospital.HospitalContract;
import com.dcbeida.activity.hospital.HospitalPresenter;
import com.dcbeida.adapter.CommonListAdapter;
import com.dcbeida.adapter.HospitalListAdapter;
import com.dcbeida.bean.HospitalBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * 通用列表
 * Created by swt on 2016/12/26.
 */

public class CommonListActivity extends BaseActivity   {
    @Bind(R.id.img_back)
    ImageView imgBack;
    @Bind(R.id.tv_title)
    TextView tvTitle;


    @Bind(R.id.myList)
    ListView myList;
    private CommonListAdapter adapter;




    @Override
    protected int getLayoutResId() {
        return R.layout.common_listview;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initParams();
        initData();
    }

    @OnClick(R.id.img_back)
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.img_back:
                finish();
                break;
        }
    }

    private void initParams() {


    }


    private List<Pair<String,Integer>> getCridetList(){
        List<Pair<String,Integer>> list = new ArrayList<>();
        list.add(new Pair<String, Integer>("身份证",0));
        list.add(new Pair<String, Integer>("护照",1));
        list.add(new Pair<String, Integer>("港澳通行证",2));
        list.add(new Pair<String, Integer>("台胞证",3));
        list.add(new Pair<String, Integer>("军人证",4));
        list.add(new Pair<String, Integer>("其他",9));
        return list;
    }

    private List<Pair<String,Integer>> getTelList(){
        List<Pair<String,Integer>> list = new ArrayList<>();
        list.add(new Pair<String, Integer>("手机号",0));
        list.add(new Pair<String, Integer>("固定电话",1));

        return list;
    }

    private void initData() {

        adapter = new CommonListAdapter(CommonListActivity.this);
        myList.setAdapter(adapter);
        Bundle bundle = getIntent().getExtras();

        int type = 0;
        tvTitle.setText("证件类型选择");
        if (null != bundle) {
            type = bundle.getInt("type");
        }
        if(type ==0){
            adapter.setmArrayList(getCridetList());
        }else if(type ==1){
            adapter.setmArrayList(getTelList());
        }

        myList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent();
                Bundle bundle = new Bundle();
                Pair<String,Integer> pair = (Pair<String,Integer>) adapter.getItem(position);
                bundle.putString("key", pair.first);
                bundle.putInt("value", pair.second);
                intent.putExtras(bundle);
                CommonListActivity.this.setResult(RESULT_OK, intent);
                CommonListActivity.this.finish();
            }
        });

    }


}
